package com.example.gitpart03.Type;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.gitpart03.R;

import java.util.List;

public class TypeLeftAdapter extends ArrayAdapter<TypeLeftItem> {
    private final int resourceId;

    public TypeLeftAdapter(Context context, int resource, List<TypeLeftItem> objects) {
        super(context, resource, objects);
        this.resourceId = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            view = inflater.inflate(resourceId, parent, false);
            holder = new ViewHolder();
            holder.textView = view.findViewById(R.id.type_yogurt);
            view.setTag(holder);
        } else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        TypeLeftItem item = getItem(position);
        if (item != null) {
            holder.textView.setText(item.getText());
        }
        return view;
    }

    private static class ViewHolder {
        TextView textView;
    }
}